
 /**
 * 打包模式(由命令行参数"--mode xxx"传入)
 * 可选值: development || production 默认为production
 * 
 * @returns {String}
 */
Object.defineProperty(exports, 'mode', {

    get: function () {

        let argv = process.argv;
        let index = argv.indexOf('--mode'); 
    
        return index > 0 ? argv[index + 1] : 'production';
    }
});



/**
 * 目录操作库
 * 
 * @type {Object}
 */
exports.directory = require('./directory');


/**
 * 发布操作库
 * 
 * @type {Object}
 */
exports.publish = require('./publish');


/**
 * 初始化平台
 * 
 * @type {Function}
 */
exports.platform = require('./platform');


/**
 * 从指定路径开始往上查找并加载webpack.rules.js
 * 
 * @param {*} startDirName 起始目录
 * @param {*} platform 平台 h5|wx|...
 * @param {*} isDevelopment 是否开发环境
 */
exports.webpackRules = function (startDirName, platform, isDevelopment) {

    let fs = require('fs');
    let path = require('path');
    let items = [];
    let file = path.join(startDirName, 'webpack.rules.js');

    while (!fs.existsSync(file))
    {
        if (items.length > 0)
        {
            break;
        }

        items.push('..');

        file = path.join(startDirName, items.join('/'), 'webpack.rules.js');
    }

    try
    {
        return require(file)(platform, isDevelopment);
    }
    catch
    {
        return require('./config/webpack.rules')(platform, isDevelopment);
    }
}
